package com.chinasoft04.mall.mapper;

import com.chinasoft04.mall.dto.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {

    @Select("select * from sp_goods where goods_name like #{query}")
    List<Goods> selectAllGoods(@Param("query") String query);

    @Select("select * from sp_goods where goods_id = #{id}")
    Good selectGoodById(@Param("id") Integer id);

    @Select("select * from sp_goods_pics where goods_id = #{id}")
    List<Picture> selectPics(@Param("id") Integer id);

    @Select("select * from sp_goods_attr a,sp_attribute b where a.attr_id = b.attr_id and goods_id = #{id}")
    List<Attr> selectAttrs(@Param("id") Integer id);

    @UpdateProvider(value = GoodSql.class,method = "updateGoodSql")
    int updateGoodInfo(@Param("id") Integer id, Good good);

    @Delete("delete from sp_goods where goods_id = #{id}")
    int deleteGood(@Param("id") Integer id);

    @Insert("insert into sp_goods(goods_name, goods_price, goods_weight,add_time,upd_time,goods_small_logo,goods_introduce,cat_one_id,cat_two_id,cat_three_id) values(#{good.goods_name}, #{good.goods_price}, #{good.goods_weight},#{good.add_time},#{good.upd_time},#{small_img},#{good.goods_introduce},#{good.cat_one_id},#{good.cat_two_id},#{good.cat_three_id}) ")
    int addGood(Good good,@Param("small_img") String smallImg);
}
